package com.greateamd.timetableasy.client.widgets;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DecoratedPopupPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class DialogPopupPanel extends DecoratedPopupPanel implements ClickHandler {

	private VerticalPanel vPanel = new VerticalPanel();
	private Button btClose = new Button("Close");
	private Button btOK = new Button("Confirm");
	
	private final DialogHandler handler;
	
	public DialogPopupPanel(Widget content,DialogHandler handler) {
		super(false, true);
		this.handler = handler;
		setGlassEnabled(true);
		setAnimationEnabled(true);
		btClose.addClickHandler(this);
		btOK.addClickHandler(this);

		vPanel.add(content);
		vPanel.add(new HTML("<br /> <hr /> "));

		HorizontalPanel hTemp = new HorizontalPanel();
		hTemp.setSpacing(5);
		hTemp.add(btClose);
		hTemp.add(btOK);
		vPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		vPanel.add(hTemp);
		super.add(vPanel);

		center();
	}

	@Override
	public void onClick(ClickEvent event) {
		hide();
		if (event.getSource().equals(btClose)) {
			handler.onCancelClick();
		} else {
			handler.onConfirmClick();
		}
	}
}
